<template>
	<view class="top-black">
		<view class="tab-bar-pla" v-if="fixed">
			<!--状态栏高度-->
			<status-bar></status-bar>
			<view class="box-height"></view>
		</view>


		<view class="tab-bar">
			<view class="bg" :style="{'opacity':bgOpacity}"></view>
			<!--状态栏高度-->
			<status-bar></status-bar>
			<view class="line">
				<view class="left-iocs">
					<i-icon name="iconfont-icon-fanhui" class="back-ioc" size="40rpx" :color="color" @click="onGoBack()" v-if="leftArrow && page_list.length > 1"></i-icon>
					<i-icon name="iconfont-icon-fanhui" class="back-ioc" size="40rpx" :color="color" @click="onGoBack()" v-if="leftArrow && !homeShow && page_list.length === 1"></i-icon>
					<i-icon name="iconfont-icon-shouye" class="back-ioc" size="40rpx" :color="color" @click="openHome()" v-if="homeShow"></i-icon>
				</view>
				<view class="left-iocs">
					<slot name="left"></slot>
				</view>
				<view class="title-line" v-if="title !== '0' && title">
					<text class="title u-line-1" :style="{'color':color}">{{title}}</text>
				</view>
				<view class="right">
					<slot name="right"></slot>
				</view>

			</view>
		</view>

		<i-select ref="kefu_show" :list="kefu_list" @confirm="onSelectKefu"></i-select>
	</view>
</template>

<script>
	export default {
		name: "top-bar",
		props: {
			title: {
				type: String,
				default: ""
			},
			homeShow: {
				type: Boolean,
				default: false
			},
			leftArrow: {
				type: Boolean,
				default: true
			},
			ScreenWhite: {
				type: Boolean,
				default: false
			},

			color: {
				type: String,
				default: '#ffffff'
			},
			fixed: {
				type: Boolean,
				default: true
			},
			bgOpacity: {
				type: [String, Number],
				default: 1
			},

			backPress: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				page_list: [],
				kefu_list: [],
			}
		},
		created() {
			this.page_list = getCurrentPages() // 获取栈实例
		},

		methods: {
			openHome() {
				uni.switchTab({
					url: "/pages/home/index"
				})

			},
			onSelectKefu(e) {
				this.openWeb(e.value)
			},
			onDownApp() {
				window.open(this.option.down_url)
			},
			onGoBack() {
				if (this.backPress) {
					//拦截返回
					this.$emit("on-back")
				} else {
					this.goBack()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tab-bar {
		position: fixed;
		top: 0px;
		width: 100%;
		/* #ifdef H5 */
		max-width: 500px;
		/* #endif */
		margin: 0 auto;
		display: flex;
		flex-direction: column;
		z-index: 99;
		padding: 0 20rpx;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			background: url("@/static/images/top-bar-bg.png");
			background-size: 100% auto;
		}

		.line {
			position: relative;
			display: flex;
			align-items: center;
			height: 88rpx;
			width: 100%;

			.left-iocs {
				z-index: 99;
				display: flex;
				align-items: center;

				.back-ioc {
					padding: 10rpx;
					margin-right: 0rpx;
				}

				.dmon-app {
					font-size: 26rpx;
					color: #ffffff;
					width: 60rpx;
					height: 60rpx;
				}
			}

			.title-line {
				position: absolute;
				left: 0;
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.title {
				font-size: 32rpx; //解决横竖屏模式下适配改变问题
				color: #000000;
			}


			.left {
				position: absolute;
				height: 88rpx;
				left: 0;
				display: flex;
				align-items: center;
			}

			.right {
				position: absolute;
				height: 88rpx;
				right: 0;
				display: flex;
				align-items: center;

				.right-line {
					display: flex;
					align-items: center;

					image {
						width: 60rpx;
						height: 60rpx;
						border-radius: 100px;
						margin-left: 10rpx;
						display: block;
					}

					.msg-view {
						position: relative;

						i {
							position: absolute;
							top: 6rpx;
							right: 0;
							display: block;
							width: 16rpx;
							height: 16rpx;
							background-color: #ff2b3f;
							border-radius: 10px;
						}
					}
				}
			}
		}

	}

	.tab-bar-pla {
		display: flex;
		flex-direction: column;
		width: 100%;

		.box-height {
			width: 100%;
			height: 88rpx;
		}
	}
</style>